package test.br.com.lh.urabuilder.util
{
	import br.com.lh.urabuilder.model.UraModelLocator;
	import br.com.lh.urabuilder.util.CoordinatesUtils;
	
	import flash.geom.Point;
	
	import flexunit.framework.TestCase;
	import flexunit.framework.TestSuite;
	
	import mx.containers.Canvas;
	import mx.containers.TabNavigator;

	public class CoordinateUtilTest extends TestCase
	{
		public function CoordinateUtilTest(methodName:String=null)
		{
			super(methodName);
		}
		
		public static function suite():TestSuite{
			var ts:TestSuite = new TestSuite();
			ts.addTest(new CoordinateUtilTest("angleInDegreesOK"));
			ts.addTest(new CoordinateUtilTest("angleInRadOK"));
			ts.addTest(new CoordinateUtilTest("canvasScaleConvertionOK"));
			return ts;
		}
		
		public function angleInDegreesOK():void{
			var startPoint:Point = new Point(0,0);
			var endPoint:Point = new Point(0,0);
			assertEquals(0,CoordinatesUtils.getAngleInDegrees(startPoint,endPoint));
			endPoint= new Point(10,0);
			assertEquals(0,CoordinatesUtils.getAngleInDegrees(startPoint,endPoint));
			endPoint= new Point(0,10);
			assertEquals(90,CoordinatesUtils.getAngleInDegrees(startPoint,endPoint));
			endPoint= new Point(0,-10);
			assertEquals(270,CoordinatesUtils.getAngleInDegrees(startPoint,endPoint));
			endPoint= new Point(-10,0);
			assertEquals(180,CoordinatesUtils.getAngleInDegrees(startPoint,endPoint));
			endPoint= new Point(10,10);
			assertEquals(45,CoordinatesUtils.getAngleInDegrees(startPoint,endPoint));
			endPoint= new Point(10,-10);
			assertEquals(315,CoordinatesUtils.getAngleInDegrees(startPoint,endPoint));
			endPoint= new Point(-10,10);
			assertEquals(135,CoordinatesUtils.getAngleInDegrees(startPoint,endPoint));
			endPoint= new Point(-10,-10);
			assertEquals(225,CoordinatesUtils.getAngleInDegrees(startPoint,endPoint));
		}
		
		public function angleInRadOK():void{
			var startPoint:Point = new Point(0,0);
			var endPoint:Point = new Point(0,0);
			assertEquals(0,CoordinatesUtils.getAngleInRad(startPoint,endPoint));
			endPoint= new Point(10,0);
			assertEquals(0,CoordinatesUtils.getAngleInRad(startPoint,endPoint));
			endPoint = new Point(0,10);
			assertEquals(Math.PI/2,CoordinatesUtils.getAngleInRad(startPoint,endPoint));
			endPoint = new Point(0,-10);
			assertEquals(-Math.PI/2,CoordinatesUtils.getAngleInRad(startPoint,endPoint));
		}
		
		public function canvasScaleConvertionOK():void{
			var tabNavigator:TabNavigator = new TabNavigator();
			tabNavigator.x = 30;
			tabNavigator.y = 30;
			var canvas:Canvas = new Canvas();
			canvas.x = 0;
			canvas.y = 12;
			tabNavigator.addChild(canvas);
			UraModelLocator.modelLocator = null;
			var modelLocator:UraModelLocator = UraModelLocator.getInstance(canvas);
			var point:Point = CoordinatesUtils.getPointConvertedIntoCanvasScale(new Point(100,100));
			assertEquals(58,point.y);
			assertEquals(70,point.x);
		}
		
		
	}
}